package com.bjxst;

import java.io.FileInputStream;

public class SecondDemo {
    public static void main(String[] args) {
        FileInputStream fis = null;
        try{
            //创建对象
            fis = new FileInputStream("d:/a.txt");
            //读取内容
            /*int temp = 0;
            while ((temp = fis.read()) != -1){
                System.out.println(temp);
            }*/
            //将字节转为字符输出
            StringBuilder sb = new StringBuilder();
            int temp = 0;
            while ((temp = fis.read()) != -1){
                System.out.println(temp);
                sb.append((char) temp); //注：char强转
            }
            System.out.println(sb.toString());
        }catch (Exception e){
            e.printStackTrace();
        }finally {  //在这里关闭流，因为当程序出现异常时IO流也会被关闭
            try{
               if(fis != null) {
                   fis.close();
               }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
